package org.lixf.socket;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class SocketTest {
    public static void main(String[] args) throws IOException {
//        test1();
        test2();
        System.out.println(123);
        System.out.println(123);

    }

    public static void test1() throws IOException {
        Socket socket = new Socket("time-a.nist.gov", 13);
        Scanner scanner = new Scanner(socket.getInputStream(), "UTF-8");
        // 一共两行 第一行为空行
        System.out.println(scanner.nextLine());
        System.out.println(scanner.nextLine());
    }

    public static void test2() throws IOException {
        Socket socket = new Socket("127.0.0.1", 8888);
        OutputStream os = socket.getOutputStream();
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8));
        writer.write("aaabbb");
        writer.flush();
    }
}
